home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
bipl.zip
/
PROCS.ZIP
/
FILENAME.ICN
< prev
next >
Wrap
Text File
|
1992-09-28
|
1KB
|
54 lines
############################################################################
#
# File: filename.icn
#
# Subject: Procedures to parse file names
#
# Author: Robert J. Alexander
#
# Date: December 5, 1989
#
###########################################################################
#
# suffix() -- Parses a hierarchical file name, returning a 2-element
# list: [prefix,suffix]. E.g. suffix("/a/b/c.d") -> ["/a/b/c","d"]
#
#
# tail() -- Parses a hierarchical file name, returning a 2-element
# list: [head,tail]. E.g. tail("/a/b/c.d") -> ["/a/b","c.d"].
#
# components() -- Parses a hierarchical file name, returning a list of
# all directory names in the file path, with the file name (tail) as
# the last element.
#
# E.g. components("/a/b/c.d") -> ["/","a","b","c.d"].
#
############################################################################
procedure suffix(s,separator)
local i
/separator := "."
i := *s + 1
every i := find(separator,s)
return [s[1:i],s[(*s >= i) + 1:0] | &null]
end
procedure tail(s,separator)
local i
/separator := "/"
i := 0
every i := find(separator,s)
return [s[1:i + (i <= 1 | 0)],"" ~== s[i + 1:0] | &null]
end
procedure components(s,separator)
local x,head
/separator := "/"
x := tail(s,separator)
return case head := x[1] of {
separator: [separator]
"": []
default: components(head)
} ||| ([&null ~=== x[2]] | [])
end